﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zoomtel.Entity.BIZ;
using Zoomtel.Persist.BIZ;
using Zoomtel.Persist.BIZ.Models;

namespace Zoomtel.Service.BIZ
{
    public class ItemPromotionService
    {
        private ItemPromotionRepository _itemRepository;
        public ItemPromotionService(ItemPromotionRepository itemRepository)
        {
            _itemRepository = itemRepository;
        }


        public async Task<IResultModel> Add(ItemPromotionEntity model)
        {
            var result = new ResultModel<int>();

            model.Id = _itemRepository.GetSeq("S_BIZ_ITEMPROMOTION").ToString();

            int i = _itemRepository.Insert(model);
            if (i > 0)
            {

                return result.Success(i);
            }
            else
            {
                return result.Failed();

            }

        }

        public async Task<IResultModel> Update(ItemPromotionEntity model)
        {
            var result = new ResultModel<int>();

            int i = _itemRepository.Update(model);
            if (i > 0)
            {

                return result.Success(i);
            }
            else
            {
                return result.Failed();

            }

        }

        public IResultModel QueryItemPromotionTotalCountInfo(ItemPromotionQueryModel model)
        {
            return ResultModel.Success(_itemRepository.QueryItemPromotionTotalCountInfo(model));
        }

        public async Task<IList<OptionResultModel>> QueryUnsettleItemList(ItemPromotionQueryModel model)
        {

            var result = _itemRepository.QueryUnsettleItemList(model);
            var list = result.Select(m => new OptionResultModel
            {
                Label = m.ItemName,
                Data = m,
                Value = m.ItemId
            }).ToList();
            return list;
        }
    }
}
